//
//  HBSearchResultCell.m
//  HeartBeat
//
//  Created by karong on 2023/8/24.
//

#import "HBSearchResultCell.h"
#import "NSString+ColorAttstr.h"

@interface HBSearchResultCell ()
@property (weak, nonatomic) IBOutlet UILabel *finishLabel;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@end

@implementation HBSearchResultCell
- (void)setDataWithObject:(HBNovelModel *)object keyWord:(NSString *)keyWord {
    [super setDataWithObject:object];
    self.finishLabel.text = object.finish_txt;
    self.scoreLabel.text = SF(@"%.1f",object.score);
    [self attNameWithObject:object keyWord:KEmptyStr(keyWord)];
}

- (void)attNameWithObject:(HBNovelModel *)object keyWord:(NSString *)keyWord {
    NSString *text = object.title;
    NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] initWithString:text
                                                                                 attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:16], NSForegroundColorAttributeName: UIColor.font_black_1A1A1A}];
    
    NSRange range1 = [text rangeOfString:keyWord];
    [attrText addAttributes:@{NSForegroundColorAttributeName: UIColor.font_yellow_FFCC00} range:range1];
    self.nameLabel.attributedText = [object.name stringWithPartHighLightSubstring:keyWord highLightColor:UIColor.font_yellow_FFCC00];
}


@end
